public class WithdrawThread implements Runnable {

    private final int amount;
    private final Account account;

    WithdrawThread(Account y, int amount) {
        account = y;
        this.amount = amount;
    }

    public void run() {
    synchronized (account) {
        if (account.getBalance() < 900) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (account.getBalance()<900){
            return;
        }
        account.withdraw(amount);
    }
    }
}